<?php
/**
 * Created by PhpStorm.
 * User: qch
 * Date: 2015/7/6
 * Time: 10:10
 */

namespace J\Util;


class DateTool
{
    public static $format = 'Y-m-d H:i:s';


    public static function getDateTime($value, $format = null)
    {

        if (empty($value)) {
            return '';
        }

        $date = date_create()->setTimestamp((int)$value);

        if ($format === null) {
            $format = static::$format;
        }

        return $date->format($format);
    }

    public static function strToInt($value)
    {
        if(is_numeric($value)) return (int)$value;

        $date = \DateTime::createFromFormat(static::$format, $value);
        if ($date) {
            return $date->getTimestamp();
        }
        return null;
    }
}